package com.ddtech.business.train.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddtech.business.train.query.TrainPlanQuery;
import com.ddtech.business.train.res.TrainPlanVo;
import com.ddtech.business.train.service.TrainPlanResourceService;
import com.ddtech.business.train.service.TrainPlanService;
import com.ddtech.framework.log.aop.log.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 培训计划表 前端控制器
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-06
 */
@Api(tags = "业务-培训计划")
@RestController
@RequestMapping("/train-plan")
public class TrainPlanController {
    @Autowired
    private TrainPlanService trainPlanService;


    @Autowired
    private TrainPlanResourceService trainPlanResourceService;



    @ApiOperation(value = "分页查询培训计划")
    @GetMapping(value = "/page-list")
    public ResponseEntity getPageList(TrainPlanQuery trainPlanQuery) {
        return new ResponseEntity(trainPlanService.pageList(trainPlanQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询培训计划")
    @GetMapping(value = "/list")
    public ResponseEntity list(TrainPlanQuery trainPlanQuery) {
        return new ResponseEntity(trainPlanService.list(trainPlanQuery.autoWrapper()), HttpStatus.OK);
    }

    @ApiOperation(value = "查询个人培训计划")
    @GetMapping(value = "/my-train-plan-list")
    public ResponseEntity getMyTrainPlanList(TrainPlanQuery trainPlanQuery) {
        return new ResponseEntity(trainPlanService.getMyTrainPlanList(trainPlanQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询个人培训计划、个人任务数量")
    @GetMapping(value = "/my-train-and-task")
    public ResponseEntity getMyTrainPlanAndMyTaskNum(TrainPlanQuery trainPlanQuery) {
        return new ResponseEntity(trainPlanService.getMyTrainPlanAndMyTaskNum(trainPlanQuery), HttpStatus.OK);
    }

    @Log("新增培训计划")
    @ApiOperation(value = "新增培训计划")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody TrainPlanVo trainPlanVo) {
        trainPlanService.create(trainPlanVo);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "培训计划详情")
    @GetMapping(value = "/info/{id}")
    public ResponseEntity info(@PathVariable String id) {
        return new ResponseEntity(trainPlanService.info(id), HttpStatus.OK);
    }


    @Log("删除培训计划程")
    @ApiOperation(value = "删除培训计划")
    @PostMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        trainPlanService.del(id);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "PC端、移动端培训详情")
    @GetMapping(value = "/getTrainInfo/{id}")
    public ResponseEntity getTrainInfo(@PathVariable String id) {
        return new ResponseEntity(trainPlanService.getTrainInfo(id), HttpStatus.OK);
    }


    @Log("pc、app移动端查询培训课程播放资源")
    @ApiOperation(value = "pc、app移动端查询培训课程播放资源")
    @GetMapping(value = "/findOne/{id}")
    public ResponseEntity findOne(@PathVariable String id) {
        return new ResponseEntity(trainPlanResourceService.findOne(id),HttpStatus.OK);
    }

    @ApiOperation(value = "培训完成情况")
    @GetMapping(value = "/train-plan-schedule/{trainId}")
    public ResponseEntity trainPlanSchedule(@PathVariable String  trainId,
                                            String userName,
                                            @RequestParam(value = "page",defaultValue = "1") int page,
                                            @RequestParam(value = "pageSize",defaultValue = "10") int pageSize) {
        IPage pageInfo = new Page(page+1, pageSize);
        return new ResponseEntity(trainPlanService.trainPlanSchedule(pageInfo,trainId,userName), HttpStatus.OK);
    }

    @ApiOperation(value = "培训考核情况")
    @GetMapping(value = "/schedule-check-list")
    public ResponseEntity getScheduleCheckList(@ApiParam("培训id") @RequestParam String trainId,
                                               @ApiParam("学员名称")  String userName,
                                               @RequestParam(value = "page", defaultValue = "1") int page,
                                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        IPage pageInfo = new Page(page + 1, pageSize);
        return new ResponseEntity(trainPlanService.getScheduleCheckList(trainId, userName,pageInfo), HttpStatus.OK);
    }
}
